using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BUS;
using Utility;
using Entities;

public partial class Admin_Danhsachtourmo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            LoadData();

        }
    }
    private void LoadData()
    {
        pager.PageSize = 5;
        Criteria cri = new Criteria();
        int total = 0;
        

        tbTourmoCollection  tourmCollection = tbTourmoBUS .Get(cri.Criter, pager.CurrentIndex, pager.PageSize,
       tbTourmoCollumn .matourmo .ToString(), OrderDirection.ASC.ToString(), out total);
        Repeater1.DataSource = tourmCollection;
        Repeater1.DataBind();

        pager.ItemCount = total;

    }

    protected void pager_Command(object sender, CommandEventArgs e)
    {
        pager.CurrentIndex = Convert.ToInt32(e.CommandArgument);
        LoadData();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        LoadData();
    }
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item
        || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            tbTourmo  tourm = (tbTourmo  )e.Item.DataItem;

          


            tbTour  tour = tbTourBUS .GetByID(tourm.Matour );
            if (tour != null)
            {
                Literal lit_tm = (Literal)e.Item.FindControl("lit_tent");
                lit_tm.Text = tour.Tentour ;
            }


            Label  lit_nm = (Label )e.Item.FindControl("lit_nm");
            lit_nm.Text = tourm.Ngaymo.ToString ()  ;



            Literal lit_nkh = (Literal)e.Item.FindControl("lit_nkh");
            lit_nkh.Text = tourm.Ngaykhoihanh.ToString () ;

            HyperLink hp_sua = (HyperLink)e.Item.FindControl("hp_sua");
            hp_sua.NavigateUrl = "~/Admin/Suatourmo.aspx?id=" + tourm.Matourmo .ToString();





        }
    }
    protected void lbt_xoa_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < Repeater1.Items.Count; i++)
        {
            CheckBox cb_xoa = (CheckBox)Repeater1.Items[i].FindControl("cb_xoa");
            if (cb_xoa.Checked == true)
            {
                HiddenField hf_id = (HiddenField)Repeater1.Items[i].FindControl("hf_id");
                int id = int.Parse(hf_id.Value);
                tbTourmo  tourm = tbTourmoBUS .GetByID(id);

              
                tbTourmoBUS.Delete(id);
            }
        }
        Response.Redirect(Request.RawUrl);
    }
}
